package com.zeekr.orm.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2025/4/17 16:35
 */
@RestController
@RequestMapping("/test")
public class ThreadPoorTestController {

  @Resource
  RabbitTemplate rabbitTemplate;

  @Resource
  ThreadPoolExecutor loginThreadPoor;

  @GetMapping("/get")
  public void get() {
    rabbitTemplate.convertAndSend("user-service-exchange","user-service","asdd111");
    CompletableFuture<String> result = CompletableFuture.supplyAsync(() -> {
      System.out.println("任务来了，线程名称：" + Thread.currentThread().getName());
      try {
        Thread.sleep(10000);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        System.out.println("线程：" + Thread.currentThread().getName() + "任务结束");
      }
      return "sss";
    }, loginThreadPoor);
  }

}
